<?php
class assignment{
	function __construct(){
		global $tpl;
		$this->tpl = $tpl;
		$user = authenticate();
		if(isset($user['user']) && $user['user_id']==1){
			$tpl->assign('user',$user);
		}else{
			redirect(BASE_URL);
		}

	}
    function view_defaults(){
		$cur_sort = !empty($_GET['sort'])?$_GET['sort']:'a_id';

		$a_title = !empty($_GET['a_title'])?$_GET['a_title']:'';
		$c_id = !empty($_GET['c_id'])?$_GET['c_id']:'';
		$cs_id= !empty($_GET['cs_id'])?$_GET['cs_id']:'';
		$a_sdate= !empty($_GET['a_sdate'])?$_GET['a_sdate']:'';
		$a_edate= !empty($_GET['a_edate'])?$_GET['a_edate']:'';

		$con['order'] = $cur_sort;
		$con['a_title'] = $a_title;
		$con['c_id'] = $c_id;
		$con['cs_id'] = $cs_id;
		$con['a_sdate'] = $a_sdate;
		$con['a_edate'] = $a_edate;

		include_once("AssignmentModel.class.php");
		$assignmentModel = new AssignmentModel();

		$assignments = $assignmentModel->getItems($con,10);
		$this->tpl->assign('total',$assignments['page']->total);

		include_once("CorporationModel.class.php");
		$corpmod = new CorporationModel();
		$corps  = $corpmod->getAllCorps();
		$this->tpl->assign('corps',$corps);
		$this->tpl->assign('assignments',$assignments);
		$this->tpl->assign('con',$con);
    }

	function view_search(){
		$cur_sort = !empty($_GET['sort'])?$_GET['sort']:'a_id';
		$c_name = !empty($_GET['c_name'])?$_GET['c_name']:'';
		$a_id = !empty($_GET['a_id'])?$_GET['a_id']:'';
		$a_desc = !empty($_GET['a_desc'])?$_GET['a_desc']:'';
		$a_title = !empty($_GET['a_title'])?$_GET['a_title']:'';

		$con['order'] = $cur_sort;
		$con['c_name'] = $c_name;
		$con['a_id'] = $a_id;
		$con['a_desc'] = $a_desc;
		$con['a_title'] = $a_title;
		$this->tpl->assign('con',$con);
	}
	function view_add(){
		$corps = array();
    	include_once("CorporationModel.class.php");
		$corpmod = new CorporationModel();
		$corps  = $corpmod->getAllCorps();

		include_once("ReportModel.class.php");
    	$reportModel = new ReportModel();
    	$reports = $reportModel->getAllReports();
    	
    	include_once 'AssignmentModel.class.php';
    	$assignmod = new AssignmentModel();
    	$describe = $assignmod->getAllDescribe();
    	
		$this->tpl->assign('corps',$corps);
		$this->tpl->assign('reports',$reports);
		$this->tpl->assign('describe',$describe);
	}
    function op_save(){
    	$msg = '';


		$pattern = "/^[a-zA-Z][a-zA-Z0-9_]{1,13}[a-zA-Z0-9]$/i";

		$_POST ['a_title'] = trim ( $_POST ['a_title'] );
		$_POST ['a_sdate'] = trim ( $_POST ['a_sdate'] );
		$_POST ['a_edate'] = trim ( $_POST ['a_edate'] );
		$_POST ['c_id'] = intval( $_POST ['c_id'] );
		//$_POST ['cs_id'] = intval ( $_POST ['cs_id'] );
		$_POST ['cs_id'] = isset( $_POST ['addstore'] )?$_POST ['addstore']:0;
		$_POST ['re_id'] = intval ( $_POST ['re_id'] );
		$_POST ['b_id'] = intval ( $_POST ['b_id'] );
		$_POST ['a_desc'] = addslashes( $_POST ['a_desc'] );
		$_POST ['a_demand'] = addslashes( $_POST ['a_demand']);
		$_POST ['a_istest'] = isset($_POST ['a_istest'])?1:0;
		$_POST ['a_quiz'] = addslashes( $_POST ['a_quiz'] );
		$_POST ['a_hasphoto'] = !isset ( $_POST ['a_hasphoto'] )?0:1;
		$_POST ['a_hasaudio'] = !isset ( $_POST ['a_hasaudio'] )?0:1;
		$_POST ['title_suffix'] = isset( $_POST ['title_suffix'] )?trim($_POST ['title_suffix']):'';

		//评论题中设置多种分制，默认为10分制 add by wendy 2010.11.23
		$_POST['a_markgrade'] = isset($_POST['a_markgrade'])?$_POST['a_markgrade']:10;

		if (empty ( $_POST ['a_title'] ) ) {
			$msg = array('s'=> 400,'m'=>lang('a_titlerule'),'d'=>'');
			exit(json_output($msg));
		}


		include_once("AssignmentModel.class.php");
		$assignmentMod = new AssignmentModel();

		//$assignment['a_title'] =  $_POST ['a_title'];
		$a_title =  $_POST ['a_title'];
		$title_suffix = $_POST ['title_suffix'];
		$cs_id =  $_POST ['cs_id'];
		
		$assignment['a_sdate'] =  $_POST ['a_sdate'];
		$assignment['a_edate'] =  $_POST ['a_edate'];
		$assignment['c_id'] =  $_POST ['c_id'];
		//$assignment['cs_id'] =  $_POST ['cs_id'];	
		$assignment['re_id'] =  $_POST ['re_id'];
		$assignment['b_id'] =  $_POST ['b_id'];
		$assignment['a_desc'] =  $_POST ['a_desc'];
		$assignment['a_demand'] =  $_POST ['a_demand'];
		$assignment['a_istest'] =  $_POST ['a_istest'];
		if($assignment['a_istest']==0) $assignment['a_quiz_pass']=1;
		if($assignment['a_istest']==1) $assignment['a_quiz_pass']=0;
		$assignment['a_quiz'] =  $_POST ['a_quiz'] ;
		$assignment['a_hasphoto'] =  $_POST ['a_hasphoto'] ;
		$assignment['a_hasaudio'] =  $_POST ['a_hasaudio'] ;

		//评分题中设置多种分制 add by wendy 2010.11.23
		$assignment['a_markgrade'] = $_POST['a_markgrade'];
		
		// 1. create db assignment
		if(isset($cs_id) && !empty($cs_id) && is_array($cs_id)){
			include_once("CorporationModel.class.php");
			$corpmod = new CorporationModel();
			
			foreach($cs_id as $key=>$val){
				$assignment['cs_id'] =  $val;
				
				$csinfo = $corpmod->getStoreById($assignment['cs_id']);
				$csname = $csinfo['cs_name'];
				$assignment['a_title'] = $a_title.' '.$csname.' '.$title_suffix;
				
				$row = $assignmentMod->createNewAssignment ($assignment);
			}
		}
		//$row = $assignmentMod->createNewAssignment ($assignment);
		if ($row !== false) {
			$msg = array('s'=> 200,'m'=>lang('success'),'d'=>$GLOBALS ['gSiteInfo'] ['www_site_url']."/admin.php/assignment/defaults");
			exit(json_output($msg));
		}
    }

    function op_delassignment(){
    	$t = true;
    	if(isset($_POST['delete']) && is_array($_POST['delete'])){
    		include_once("AssignmentModel.class.php");
    		$assignment = new AssignmentModel();
    		foreach ($_POST['delete'] as $u){

    			$t *= $assignment->deleteAssignment($u);

    		}

    		if($t) show_message_goback(lang('success'));
    	}
    	show_message(lang('selectone'));
    	goback();
    }

    function view_edit(){

    	$a_id = $_GET['a_id'];
 		$brands = $corp = array();
    	include_once("CorporationModel.class.php");
    	$corp = new CorporationModel();
    	$corps  = $corp->getAllCorps();



    	include_once("AssignmentModel.class.php");
    	$assignment = new AssignmentModel();
    	$info = $assignment->getAssignmentById($a_id);

    	$store = $corp->getStoreById($info['cs_id']);

    	$info['cs_abbr'] = $store['cs_abbr'];
    	$info['cs_name'] = $store['cs_name'];
    	$info['b_id'] = $store['b_id'];

    	$brands  = $corp->getBrandByCid($store['c_id']);
    	include_once("ReportModel.class.php");
    	$reportModel = new ReportModel();
    	$reports = $reportModel->getAllReports();

		$this->tpl->assign('corps',$corps);
		$this->tpl->assign('brands',$brands);
		$this->tpl->assign('reports',$reports);
    	$this->tpl->assign('info',$info);
    }
    function op_update(){
    	$msg = '';
		if (empty ( $_POST ['a_title'] ) ) {
			$msg = array('s'=> 400,'m'=>lang('a_titlerule'),'d'=>'');
			exit(json_output($msg));
		}

		$a_id = $_POST['a_id'];

		include_once("AssignmentModel.class.php");
		$assignment = new AssignmentModel();

		$updates['a_title'] = empty($_POST ['a_title'])?"":addslashes($_POST ['a_title']);
		$updates['a_desc'] = empty($_POST ['a_desc'])?"":addslashes($_POST ['a_desc']);
		$updates['a_demand'] = empty($_POST ['a_demand'])?"":addslashes($_POST ['a_demand']);
		$updates['a_istest'] = isset($_POST ['a_istest'])?1:0;
		if($updates['a_istest']==0) $updates['a_quiz_pass'] =1;
		if($updates['a_istest']==1) $updates['a_quiz_pass'] =0;
		$updates['a_quiz'] = empty($_POST ['a_quiz'])?"":($_POST ['a_quiz']);
		$updates['a_sdate'] = empty($_POST ['a_sdate'])?"":trim($_POST ['a_sdate']);
		$updates['a_edate'] =empty($_POST ['a_edate'])?"":trim($_POST ['a_edate']);
		$updates['c_id'] =empty($_POST ['c_id'])?"0":intval($_POST ['c_id']);
		$updates['cs_id'] =empty($_POST ['cs_id'])?"0":intval($_POST ['cs_id']);
		$updates['re_id'] =empty($_POST ['re_id'])?"0":intval($_POST ['re_id']);
		$updates['b_id'] =empty($_POST ['b_id'])?"0":intval($_POST ['b_id']);
		$updates['a_hasphoto'] =!isset($_POST ['a_hasphoto'])?"0":intval($_POST ['a_hasphoto']);
		$updates['a_hasaudio'] =!isset($_POST ['a_hasaudio'])?"0":intval($_POST ['a_hasaudio']);

		//评论题中设置多种分制，默认为10分制 add by wendy 2010.11.23
		$updates['a_markgrade'] = isset($_POST['a_markgrade'])?$_POST['a_markgrade']:10;

		// 1. update db assignment
		$row = $assignment->updateAssignment( $updates, $a_id);
		if ($row !== false) {

			$msg = array('s'=> 200,'m'=>lang('success'),'d'=>'');
			exit(json_output($msg));

		}else{
			$msg = array('s'=> 400,'m'=>lang('failed'),'d'=>'');
			exit(json_output($msg));
		}
    }

    function view_applicant(){
    	$a_id = $_GET['a_id'];
    	$b_id = $_GET['b_id'];

    	$a_title = urldecode($_GET['a_title']);

    	include_once("AssignmentModel.class.php");
    	$assignment = new AssignmentModel();
    	$applicant = $assignment->getAssignmentApplicantById($a_id);

    	include_once("UserModel.class.php");
    	$user = new UserModel();
    	foreach($applicant as $k=>$v){
    		$user_id = $v['user_id'];
    		$compassign = $user->db->getRow("select count(*) from assignment where user_id='$user_id' and a_finish=1.00 and b_id='$b_id'");
    		$totalcomp = $user->db->getRow("select count(*) from assignment where user_id='$user_id' and a_finish=1.00");

    		$applicant[$k]['completedassign'] = $compassign['count(*)'];
    		$applicant[$k]['totalcompleted'] = $totalcomp['count(*)'];
    	}

    	$this->tpl->assign('applicant',$applicant);
    	$this->tpl->assign('a_id',$a_id);
    	$this->tpl->assign('b_id',$b_id);
    	$this->tpl->assign('a_title', $a_title);

//    	echo "<pre/>";
//    	print_r($applicant);
    }

    function view_apptoexcel(){
    	$a_id = $_GET['a_id'];
    	$b_id = $_GET['b_id'];
    	$a_title = $_GET['a_title'];

    	include_once("AssignmentModel.class.php");
    	$assignment = new AssignmentModel();
    	$applicant = $assignment->getAssignmentApplicantById($a_id);

    	include_once("UserModel.class.php");
    	$user = new UserModel();
    	foreach($applicant as $k=>$v){
    		$user_id = $v['user_id'];
    		$compassign = $user->db->getRow("select count(*) from assignment where user_id='$user_id' and a_finish=1.00 and b_id='$b_id'");

    		$applicant[$k]['completedassign'] = $compassign['count(*)'];
    	}
//    	echo count($applicant);

		/** 导出为EXCEL start **/

		/** Error reporting */
		error_reporting(E_ALL);

		//date_default_timezone_set('Europe/London');

		/** PHPExcel */
		require_once 'plugins/phpexcel/Classes/PHPExcel.php';


		// Create new PHPExcel object
		$objPHPExcel = new PHPExcel();

		// Set properties
		$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
									 ->setLastModifiedBy("Maarten Balliauw")
									 ->setTitle("Office 2007 XLSX Test Document")
									 ->setSubject("Office 2007 XLSX Test Document")
									 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
									 ->setKeywords("office 2007 openxml php")
									 ->setCategory("Test result file");

		//设置标题
		$objPHPExcel->setActiveSheetIndex(0)
		            ->setCellValue('A1', $a_title)
		            ->setCellValue('A2', 'ID')
		            ->setCellValue('B2', '姓名')
		            ->setCellValue('C2', '昵称')
		            ->setCellValue('D2', '已完成任务数')
		            ->setCellValue('E2', '性别')
		            ->setCellValue('F2', '手机')
		            ->setCellValue('G2', '职业')
		            ->setCellValue('H2', '月薪')
		            ->setCellValue('I2', '生日');

		//设置表格内容
		for($i=0,$j=3;$i<count($applicant); $i++){
			$v = $applicant[$i];
			if($v['income']==1) $income='<3,000';
			if($v['income']==2) $income='3,000-6,000';
			if($v['income']==3) $income='6,000-9,000';
			if($v['income']==4) $income='9,000-12,000';
			if($v['income']==5) $income='12,000-15,000';
			if($v['income']==6) $income='15,000-30,000';
			if($v['income']==7) $income='>30,000';

			$objPHPExcel->setActiveSheetIndex(0)
						->setCellValue('A'.$j, $v['user_id'])
						->setCellValue('B'.$j, $v['realname'])
						->setCellValue('C'.$j, $v['nickname'])
						->setCellValue('D'.$j, $v['completedassign'])
						->setCellValue('E'.$j, $v['gender']==1?'先生':'女士')
						->setCellValue('F'.$j, $v['mobile'])
						->setCellValue('G'.$j, $v['occupation'])
						->setCellValue('H'.$j, $income)
						->setCellValue('I'.$j, $v['birthdate']);
			$j++;
		}
		$objPHPExcel->setActiveSheetIndex(0);

		// Rename sheet
		$objPHPExcel->getActiveSheet()->setTitle($a_title);


		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);


		// Redirect output to a client’s web browser (Excel2007)
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
		header('Content-Disposition: attachment;filename="applicant.xlsx"');
		header('Cache-Control: max-age=0');

		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter->save('php://output');
		exit;
		/** 导出为EXCEL end **/

    }

    function op_choose(){
    	$a_id = $_POST['a_id'];
    	$s = $_POST['s'];
    	include_once("AssignmentModel.class.php");
    	$assignment = new AssignmentModel();
    	$rs= $assignment->chooseApplicant($a_id,$s);

    	if($rs){
    		$assignment = $assignment->getAssignmentById($a_id);
    		$field['m_pid'] = 0;
			$field['m_title'] = "任务来了！<!--!-->New assignment came!";
			$field['m_content'] = '你申请的任务('.splitx($assignment['a_title']).')已经指派给您。<a href="/index.php/home/assignment/a_id/'.$a_id.'">马上查看任务详情！</a><!--!-->The assignment that you had applied has been assigned to you. <a href="/index.php/home/assignment/a_id/'.$a_id.'">Go to see!</a>';
			$field['to_user_id'] = $assignment['user_id'];
			$field['to_user_nickname'] = $assignment['user_nickname'];
			$field['m_date'] ="MY_F:NOW()";
			include_once("MsgBoxModel.class.php");
			$msgModel = new MsgBoxModel();
			$rs = $msgModel->saveMsg($field,'msg_box');

    	}
    	show_message(lang("success"));
    	//goback( );
    }

    function view_assignto(){
    	$a_id = $_GET['a_id'];
 		$this->tpl->assign('a_id',$a_id);
    }
    function op_assignto(){
    	$msg = '';
    	$msg = array('s'=> 400,'m'=>lang('usernotexist'),'d'=>'');
    	$a_id = $_POST['a_id'];
    	$user = $_POST['user'];
    	include_once("AssignmentModel.class.php");
    	$assignment = new AssignmentModel();
    	$rs= $assignment->assignToUser($a_id,$user);

    	if($rs){
    		$assignment = $assignment->getAssignmentById($a_id);
    		$field['m_pid'] = 0;
			$field['m_title'] = "任务来了！<!--!-->New assignment came!";
			$field['m_content'] = '你申请的任务('.splitx($assignment['a_title']).')已经指派给您。<a href="/index.php/home/assignment/a_id/'.$a_id.'">马上查看任务详情！</a><!--!-->The assignment that you had applied has been assigned to you. <a href="/index.php/home/assignment/a_id/'.$a_id.'">Go to see!</a>';
			$field['to_user_id'] = $assignment['user_id'];
			$field['to_user_nickname'] = $assignment['user_nickname'];
			$field['m_date'] ="MY_F:NOW()";
			include_once("MsgBoxModel.class.php");
			$msgModel = new MsgBoxModel();
			$rs = $msgModel->saveMsg($field,'msg_box');
			$msg = array('s'=> 200,'m'=>lang('success'),'d'=>'');
    	}
    		exit(json_output($msg));
    }


    /**  新增方法 By wendy 2011.8.16  start **/

    function view_tobeassign(){
    	$cur_sort = !empty($_GET['sort'])?$_GET['sort']:'a_id';

		$a_title = !empty($_GET['a_title'])?$_GET['a_title']:'';
		$c_id = !empty($_GET['c_id'])?$_GET['c_id']:'';
		$cs_id= !empty($_GET['cs_id'])?$_GET['cs_id']:'';
		$a_sdate= !empty($_GET['a_sdate'])?$_GET['a_sdate']:'';
		$a_edate= !empty($_GET['a_edate'])?$_GET['a_edate']:'';

		$con['order'] = $cur_sort;
		$con['a_title'] = $a_title;
		$con['c_id'] = $c_id;
		$con['cs_id'] = $cs_id;
		$con['a_sdate'] = $a_sdate;
		$con['a_edate'] = $a_edate;

		$con['user_id']=0;//未指定执行人

		include_once("AssignmentModel.class.php");
		$assignmentModel = new AssignmentModel();

		$assignments = $assignmentModel->getItems($con,10);
		$this->tpl->assign('total',$assignments['page']->total);

		include_once("CorporationModel.class.php");
		$corpmod = new CorporationModel();
		$corps  = $corpmod->getAllCorps();
		$this->tpl->assign('corps',$corps);
		$this->tpl->assign('assignments',$assignments);
		$this->tpl->assign('con',$con);
    }
    function view_finished(){
    	$cur_sort = !empty($_GET['sort'])?$_GET['sort']:'a_id';

		$a_title = !empty($_GET['a_title'])?$_GET['a_title']:'';
		$c_id = !empty($_GET['c_id'])?$_GET['c_id']:'';
		$cs_id= !empty($_GET['cs_id'])?$_GET['cs_id']:'';
		$a_sdate= !empty($_GET['a_sdate'])?$_GET['a_sdate']:'';
		$a_edate= !empty($_GET['a_edate'])?$_GET['a_edate']:'';

		$con['order'] = $cur_sort;
		$con['a_title'] = $a_title;
		$con['c_id'] = $c_id;
		$con['cs_id'] = $cs_id;
		$con['a_sdate'] = $a_sdate;
		$con['a_edate'] = $a_edate;

		$con['a_auditbill']=1;//已通过发票审核

		include_once("AssignmentModel.class.php");
		$assignmentModel = new AssignmentModel();

		$assignments = $assignmentModel->getItems($con,10);
		$this->tpl->assign('total',$assignments['page']->total);

		include_once("CorporationModel.class.php");
		$corpmod = new CorporationModel();
		$corps  = $corpmod->getAllCorps();
		$this->tpl->assign('corps',$corps);
		$this->tpl->assign('assignments',$assignments);
		$this->tpl->assign('con',$con);
    }
    function view_executing(){
		header( "Location: /admin.php/assignment/assigned");
    }
    function view_assigned(){
    	$cur_sort = !empty($_GET['sort'])?$_GET['sort']:'a_id';

		$a_title = !empty($_GET['a_title'])?$_GET['a_title']:'';
		$c_id = !empty($_GET['c_id'])?$_GET['c_id']:'';
		$cs_id= !empty($_GET['cs_id'])?$_GET['cs_id']:'';
		$a_sdate= !empty($_GET['a_sdate'])?$_GET['a_sdate']:'';
		$a_edate= !empty($_GET['a_edate'])?$_GET['a_edate']:'';

		$con['order'] = $cur_sort;
		$con['a_title'] = $a_title;
		$con['c_id'] = $c_id;
		$con['cs_id'] = $cs_id;
		$con['a_sdate'] = $a_sdate;
		$con['a_edate'] = $a_edate;

		$con['user_id']=1;//已指定执行人
		$con['a_finish']=0;//任务进度为0

		include_once("AssignmentModel.class.php");
		$assignmentModel = new AssignmentModel();

		$assignments = $assignmentModel->getItems($con,10);
		$this->tpl->assign('total',$assignments['page']->total);

		include_once("CorporationModel.class.php");
		$corpmod = new CorporationModel();
		$corps  = $corpmod->getAllCorps();
		$this->tpl->assign('corps',$corps);
		$this->tpl->assign('assignments',$assignments);
		$this->tpl->assign('con',$con);

		$this->tpl->assign('type','assigned');
    }
    function view_quizpass(){
    	$cur_sort = !empty($_GET['sort'])?$_GET['sort']:'a_id';

		$a_title = !empty($_GET['a_title'])?$_GET['a_title']:'';
		$c_id = !empty($_GET['c_id'])?$_GET['c_id']:'';
		$cs_id= !empty($_GET['cs_id'])?$_GET['cs_id']:'';
		$a_sdate= !empty($_GET['a_sdate'])?$_GET['a_sdate']:'';
		$a_edate= !empty($_GET['a_edate'])?$_GET['a_edate']:'';

		$con['order'] = $cur_sort;
		$con['a_title'] = $a_title;
		$con['c_id'] = $c_id;
		$con['cs_id'] = $cs_id;
		$con['a_sdate'] = $a_sdate;
		$con['a_edate'] = $a_edate;

		$con['a_finish']=0.25;//任务进度为0.25
		$con['a_quiz_pass']=1;//小测试通过

		include_once("AssignmentModel.class.php");
		$assignmentModel = new AssignmentModel();

		$assignments = $assignmentModel->getItems($con,10);
		$this->tpl->assign('total',$assignments['page']->total);

		include_once("CorporationModel.class.php");
		$corpmod = new CorporationModel();
		$corps  = $corpmod->getAllCorps();
		$this->tpl->assign('corps',$corps);
		$this->tpl->assign('assignments',$assignments);
		$this->tpl->assign('con',$con);

		$this->tpl->assign('type','quizpass');
    }
    function view_questionpost(){
    	$cur_sort = !empty($_GET['sort'])?$_GET['sort']:'a_id';

		$a_title = !empty($_GET['a_title'])?$_GET['a_title']:'';
		$c_id = !empty($_GET['c_id'])?$_GET['c_id']:'';
		$cs_id= !empty($_GET['cs_id'])?$_GET['cs_id']:'';
		$a_sdate= !empty($_GET['a_sdate'])?$_GET['a_sdate']:'';
		$a_edate= !empty($_GET['a_edate'])?$_GET['a_edate']:'';

		$con['order'] = $cur_sort;
		$con['a_title'] = $a_title;
		$con['c_id'] = $c_id;
		$con['cs_id'] = $cs_id;
		$con['a_sdate'] = $a_sdate;
		$con['a_edate'] = $a_edate;

		$con['a_finish']=0.50;//任务进度为0.5

		include_once("AssignmentModel.class.php");
		$assignmentModel = new AssignmentModel();

		$assignments = $assignmentModel->getItems($con,10);
		$this->tpl->assign('total',$assignments['page']->total);

		include_once("CorporationModel.class.php");
		$corpmod = new CorporationModel();
		$corps  = $corpmod->getAllCorps();
		$this->tpl->assign('corps',$corps);
		$this->tpl->assign('assignments',$assignments);
		$this->tpl->assign('con',$con);

		$this->tpl->assign('type','questionpost');
    }
    function view_auditpass(){
    	$cur_sort = !empty($_GET['sort'])?$_GET['sort']:'a_id';

		$a_title = !empty($_GET['a_title'])?$_GET['a_title']:'';
		$c_id = !empty($_GET['c_id'])?$_GET['c_id']:'';
		$cs_id= !empty($_GET['cs_id'])?$_GET['cs_id']:'';
		$a_sdate= !empty($_GET['a_sdate'])?$_GET['a_sdate']:'';
		$a_edate= !empty($_GET['a_edate'])?$_GET['a_edate']:'';

		$con['order'] = $cur_sort;
		$con['a_title'] = $a_title;
		$con['c_id'] = $c_id;
		$con['cs_id'] = $cs_id;
		$con['a_sdate'] = $a_sdate;
		$con['a_edate'] = $a_edate;

		$con['a_finish']=0.75;//任务进度为0.5
		$con['a_audit']=1;

		include_once("AssignmentModel.class.php");
		$assignmentModel = new AssignmentModel();

		$assignments = $assignmentModel->getItems($con,10);
		$this->tpl->assign('total',$assignments['page']->total);

		include_once("CorporationModel.class.php");
		$corpmod = new CorporationModel();
		$corps  = $corpmod->getAllCorps();
		$this->tpl->assign('corps',$corps);
		$this->tpl->assign('assignments',$assignments);
		$this->tpl->assign('con',$con);

		$this->tpl->assign('type','auditpass');
    }
    /**  新增方法 By wendy 2011.8.16  end **/
    
    function view_gethistory(){
    	$user_id = $_GET['user_id'];
    	$user_name = $_GET['user_name'];
    	
    	include_once("AssignmentModel.class.php");
		$assignmentModel = new AssignmentModel();
		$myassignment = $assignmentModel->getMyHistoryAssignments($user_id);
		
		$this->tpl->assign("myassignment",$myassignment);
		$this->tpl->assign("username",$user_name);
    }
    
    function view_describe(){
    	include_once("AssignmentModel.class.php");
    	$assignModel = new AssignmentModel();
    	
    	$describes = $assignModel->getAllDescribe();
    	$total = count($describes);
    	
    	$this->tpl->assign('total', $total);
    	$this->tpl->assign('describes',$describes);
    	$this->tpl->assign('type','desc_list');
    }
    
    function view_newdescribe(){
    	$this->tpl->assign('type','new_desc');
    }
    function op_savedesc() {
    	$title = trim($_POST['desc_title']);
    	$describe = trim($_POST['describe']);
    	$demand = trim($_POST['demand']);
    	$quiz = trim($_POST['quiz']);
    	
    	$data = array();
    	$data['desc_title'] = $title;
    	$data['describe'] = $describe;
    	$data['demand'] = $demand;
    	$data['quiz'] = $quiz;
    	$data['desc_id'] = isset($_POST['desc_id'])?$_POST['desc_id']:'';
    	
    	include_once("AssignmentModel.class.php");
    	$assignModel = new AssignmentModel();
    	
    	$r = $assignModel->savedesc($data, 'describe_demand');
    	if($r){
    		$msg = array('s'=> 200,'m'=>lang('success'),'d'=>'');
			exit(json_output($msg));
    	}
    }
    function view_descdetail(){
    	$desc_id = !empty($_GET['desc_id'])?$_GET['desc_id']:'';
    	
    	if($desc_id){
    		include_once 'AssignmentModel.class.php';
    		$assignmod = new AssignmentModel();
    		
    		$describe = $assignmod->getDescribeById($desc_id);
    		
    		$this->tpl->assign('describe', $describe);
    	}
    }
    function view_descedit(){
    	$desc_id = !empty($_GET['desc_id'])?$_GET['desc_id']:'';
    	
    	if($desc_id){
    		include_once 'AssignmentModel.class.php';
    		$assignmod = new AssignmentModel();
    		
    		$describe = $assignmod->getDescribeById($desc_id);
    		
    		$this->tpl->assign('describe', $describe);
    	}
    }
    function op_deldesc(){
    	$t = true;
    	if(isset($_POST['delete']) && is_array($_POST['delete'])){
    		include_once("AssignmentModel.class.php");
    		$assignment = new AssignmentModel();
    		foreach ($_POST['delete'] as $u){
    			$data = array();
    			$data['deleteflag'] = 1;
    			$data['desc_id'] = $u;

    			$t *= $assignment->delDescribe($data);

    		}

    		if($t) show_message_goback(lang('success'));
    	}
    	show_message(lang('selectone'));
    	goback();
    }
    
	function view_ajaxdesc(){
	    	$desc_id = !empty($_GET['desc_id'])?$_GET['desc_id']:'';
	    	
	    	if($desc_id){
	    		include_once 'AssignmentModel.class.php';
	    		$assignmod = new AssignmentModel();
	    		
	    		$describe = $assignmod->getDescribeById($desc_id);
	    	}
	    	
	    	if(is_array($describe)){
				$descinfo['describe'] = $describe['describe'];
				$descinfo['demand'] = $describe['demand'];
				$descinfo['quiz'] = $describe['quiz'];
			}
	    	$msg = array('s'=> 200,'m'=>'ok','d'=>json_encode($descinfo));
			exit(json_output($msg));
	    }
}
?>